var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util.js")), a = getApp();

Page({
    data: {
        page: 1,
        windowWidth: wx.getSystemInfoSync().windowWidth,
        windowHeight: wx.getSystemInfoSync().windowHeight,
        saveShow: !1,
        canShow: !1,
        popShow: !1
    },
    onLoad: function(t) {
        t.id && this.setData({
            id: t.id
        }), this.getData(), wx.setNavigationBarTitle({
            title: "直播授权码"
        });
    },
    init: function() {
        this.setData({
            posterId: "",
            page: 1,
            last_page: 1,
            current_page: 1
        });
    },
    cancelPopshow: function(t) {
        this.setData({
            popShow: !1,
            posterId: "",
            shareName: ""
        });
    },
    tapCatch: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.item, e = t.currentTarget.dataset.key;
        this.setData({
            posterId: a.id,
            shareName: a.level_name
        }), "1" == a.is_sold ? this.setData({
            popShow: !0
        }) : (this.data.info[e].show = !this.data.info[e].show, this.setData({
            info: this.data.info
        }));
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), this.getMore();
        }
    },
    onShareAppMessage: function() {
        var t = "", a = "";
        return this.data.posterId ? (t = this.data.shareName, a = "/packageH/liveAuthorization/liveAuthorization_pay/liveAuthorization_pay?id=" + this.data.posterId) : (t = "直播授权码", 
        a = "/packageH/liveAuthorization/liveAuthorization_collection/liveAuthorization_collection?id=" + this.data.id), 
        {
            title: t,
            path: a
        };
    },
    getData: function() {
        var e = this, o = a.getNetAddresss("plugin.room.frontend.code.waitPay");
        a._getNetWork({
            url: o,
            data: {
                level_id: e.data.id,
                page: e.data.page
            },
            success: function(a) {
                var o = a.data;
                if (1 == o.result) {
                    for (var n = 0; n < o.data.data.length; n++) o.data.data[n].show = !1, o.data.data[n].created_at = t.default.formatTimeTwo(o.data.data[n].created_at, "Y/M/D h:m:s");
                    e.setData({
                        info: o.data.data,
                        current_page: o.data.current_page,
                        last_page: o.data.last_page
                    }), console.log(e.data.info);
                } else wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMore: function() {
        var t = this, e = a.getNetAddresss("plugin.room.frontend.code.waitPay");
        a._getNetWork({
            url: e,
            data: {
                level_id: t.data.id,
                page: t.data.page
            },
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    for (var o = 0; o < e.data.data.length; o++) e.data.data[o].show = !1;
                    t.setData({
                        info: t.data.info.concat(e.data.data),
                        current_page: e.data.current_page,
                        last_page: e.data.last_page
                    }), console.log(t.data.info);
                } else wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getPoster: function() {
        this.setData({
            canShow: !0,
            popShow: !1
        });
        var t = this;
        setTimeout(function() {
            wx.createSelectorQuery().select(".mycanvas").boundingClientRect(function(a) {
                console.log("rect", a), t.setData({
                    canvasWidth: a.width,
                    canvasHeight: a.height
                });
            }).exec();
        }, 300), wx.showLoading({
            title: "海报加载中"
        });
        var e = a.getNetAddresss("plugin.room.frontend.goods-poster.new-goods-poster");
        a._getNetWork({
            url: e,
            data: {
                id: t.data.posterId
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? (wx.hideLoading({
                    success: function(t) {}
                }), t.downfile(e.data)) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    downfileCode: function(t) {
        var a = this;
        wx.downloadFile({
            url: t,
            success: function(t) {
                var e = t.tempFilePath;
                a.setData({
                    codeImg: e
                }), a.bgImg();
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    downfile: function(t) {
        var a = this, e = this, o = t.qrcode;
        wx.downloadFile({
            url: t.backgroundImg,
            success: function(t) {
                var n = t.tempFilePath;
                a.setData({
                    backgroundImg: n
                }), e.downfileCode(o);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    bgImg: function() {
        var t = wx.createCanvasContext("canvas"), a = this.data.backgroundImg, e = this.data.codeImg;
        t.drawImage(a, 0, 0, this.data.canvasWidth, this.data.canvasHeight), t.drawImage(e, this.data.canvasWidth - 110, this.data.canvasHeight - 110, 90, 90), 
        t.draw(!0, this.popClose);
    },
    popClose: function() {
        var t = this, a = this;
        setTimeout(function() {
            wx.canvasToTempFilePath({
                x: 0,
                y: 0,
                width: t.data.canvasWidth,
                height: t.data.canvasHeight,
                destWidth: t.data.canvasWidth,
                destHeight: t.data.canvasHeight,
                canvasId: "canvas",
                success: function(t) {
                    wx.hideLoading({
                        success: function(t) {}
                    }), a.setData({
                        saveShow: !0,
                        saveImg: t.tempFilePath
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }, 300);
    },
    saveImge: function(t) {
        console.log("11111111"), wx.saveImageToPhotosAlbum({
            filePath: this.data.saveImg,
            success: function(t) {
                wx.showToast({
                    title: "图片保存成功",
                    icon: "success",
                    duration: 2e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        }), wx.getSetting({
            success: function(t) {
                console.log(t.authSetting["scope.writePhotosAlbum"]), 0 == t.authSetting["scope.writePhotosAlbum"] && wx.showModal({
                    content: "检测到您拒绝相册授权，是否去设置打开？",
                    confirmText: "确认",
                    cancelText: "取消",
                    success: function(t) {
                        t.confirm && wx.openSetting({
                            success: function(t) {}
                        });
                    }
                });
            }
        });
    },
    onClose: function(t) {
        this.setData({
            canShow: !1,
            saveShow: !1
        });
    }
});